LFP
LFP Extraction¶
First, we select the NWB file, which corresponds to the dataset we want to extract LFP from¶
nwb_file_name = "tonks20211103_.nwb"
import os
os.environ["SPYGLASS_BASE_DIR"] = "/stelmo/nwb"
os.environ["DJ_SUPPORT_FILEPATH_MANAGEMENT"] = "TRUE"
Create the standard LFP Filters. This only needs to be done once.¶
from spyglass.common import FirFilterParameters
FirFilterParameters().create_standard_filters()
FirFilterParameters()
[2023-07-10 17:05:13,993][INFO]: Connecting edeno@lmf-db.cin.ucsf.edu:3306
[2023-07-10 17:05:14,057][INFO]: Connected edeno@lmf-db.cin.ucsf.edu:3306
/home/edeno/miniconda3/envs/spyglass/lib/python3.9/site-packages/position_tools/core.py:3: DeprecationWarning: Please use `gaussian_filter1d` from the `scipy.ndimage` namespace, the `scipy.ndimage.filters` namespace is deprecated.
from scipy.ndimage.filters import gaussian_filter1d
/home/edeno/miniconda3/envs/spyglass/lib/python3.9/site-packages/pyfftw/interfaces/__init__.py:268: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
has_scipy_fft = _LooseVersion(scipy.__version__) >= _LooseVersion('1.4.0')
/home/edeno/miniconda3/envs/spyglass/lib/python3.9/site-packages/pyfftw/interfaces/__init__.py:268: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
has_scipy_fft = _LooseVersion(scipy.__version__) >= _LooseVersion('1.4.0')
| filter_name descriptive name of this filter | filter_sampling_rate sampling rate for this filter | filter_type | filter_low_stop lowest frequency for stop band for low frequency side of filter | filter_low_pass lowest frequency for pass band of low frequency side of filter | filter_high_pass highest frequency for pass band for high frequency side of filter | filter_high_stop highest frequency for stop band of high frequency side of filter | filter_comments comments about the filter | filter_band_edges numpy array containing the filter bands (redundant with individual parameters) | filter_coeff numpy array containing the filter coefficients |
|---|---|---|---|---|---|---|---|---|---|
| Delta 0.5-4 Hz | 1000 | lowpass | 0.25 | 0.5 | 4.0 | 5.0 | delta filter for 1 KHz data | =BLOB= | =BLOB= |
| Delta 0.5-4 Hz pass, 0.25-4.5 Hz stop | 1000 | lowpass | 0.25 | 0.5 | 4.0 | 4.5 | revised delta filter for 1 KHz data | =BLOB= | =BLOB= |
| Fast Gamma 65-100 Hz | 1000 | bandpass | 55.0 | 65.0 | 100.0 | 110.0 | slow gamma filter for 1 Khz data | =BLOB= | =BLOB= |
| LFP 0-400 Hz | 1000 | lowpass | 0.0 | 0.0 | 400.0 | 425.0 | LFP filter for referencing | =BLOB= | =BLOB= |
| LFP 0-400 Hz | 20000 | lowpass | 0.0 | 0.0 | 400.0 | 425.0 | standard LFP filter for 20 KHz data | =BLOB= | =BLOB= |
| LFP 0-400 Hz | 30000 | lowpass | 0.0 | 0.0 | 400.0 | 425.0 | standard LFP filter for 20 KHz data | =BLOB= | =BLOB= |
| LFP 300-495 Hz | 1000 | bandpass | 275.0 | 300.0 | 495.0 | 499.9 | estimated EMG LFP filter for 1KHz data | =BLOB= | =BLOB= |
| Ripple 150-250 Hz | 1000 | lowpass | 140.0 | 150.0 | 250.0 | 260.0 | ripple band filter for 1 kHz data | =BLOB= | =BLOB= |
| ripple_150_250 | 1000 | bandpass | 140.0 | 150.0 | 250.0 | 260.0 | 150-250 Hz pass, 140-260 Hz stop | =BLOB= | =BLOB= |
| Slow Gamma 25-55 Hz | 1000 | bandpass | 20.0 | 25.0 | 55.0 | 60.0 | slow gamma filter for 1 Khz data | =BLOB= | =BLOB= |
| Theta 5-11 Hz | 1000 | lowpass | 4.0 | 5.0 | 11.0 | 12.0 | theta filter for 1 KHz data | =BLOB= | =BLOB= |
| Theta 5-11 Hz pass, 4.5-12 Hz stop | 1000 | lowpass | 4.5 | 5.0 | 11.0 | 12.0 | revised theta filter for 1 KHz data | =BLOB= | =BLOB= |
...
Total: 13
Now we create an lfp electrode group that defines the set of electrodes we want to filter for lfp data.¶
In this case we'll take the CA1 electrodes. First we need to get the list of electrodes that are in CA1.
from spyglass.common import Electrode, BrainRegion
import pandas as pd
electrodes_df = (
pd.DataFrame(
(Electrode & {"nwb_file_name": nwb_file_name, "probe_electrode": 0})
* BrainRegion
)
.loc[:, ["nwb_file_name", "electrode_id", "region_name"]]
.sort_values(by="electrode_id")
)
electrodes_df
| nwb_file_name | electrode_id | region_name | |
|---|---|---|---|
| 0 | tonks20211103_.nwb | 0 | ca1 |
| 1 | tonks20211103_.nwb | 4 | ca1 |
| 12 | tonks20211103_.nwb | 8 | ca1 |
| 23 | tonks20211103_.nwb | 12 | ca1 |
| 34 | tonks20211103_.nwb | 16 | |
| ... | ... | ... | ... |
| 55 | tonks20211103_.nwb | 236 | ca1 |
| 57 | tonks20211103_.nwb | 240 | ca1 |
| 58 | tonks20211103_.nwb | 244 | ca1 |
| 59 | tonks20211103_.nwb | 248 | ca1 |
| 60 | tonks20211103_.nwb | 252 | ca1 |
64 rows × 3 columns
Then we create the electrode group with those electrodes by passing in the list of electrodes to the ElectrodeGroup constructor.
from spyglass.lfp.v1 import LFPElectrodeGroup
lfp_electrode_ids = electrodes_df.loc[
electrodes_df.region_name == "ca1"
].electrode_id
lfp_electrode_group_name = "CA1_test"
lfp_eg_key = {
"nwb_file_name": nwb_file_name,
"lfp_electrode_group_name": lfp_electrode_group_name,
}
LFPElectrodeGroup.create_lfp_electrode_group(
nwb_file_name=nwb_file_name,
group_name=lfp_electrode_group_name,
electrode_list=lfp_electrode_ids,
)
We now look at the list of electrodes that are part of this lfp electrode group to verify that we got the right ones¶
LFPElectrodeGroup().LFPElectrode() & {"nwb_file_name": nwb_file_name}
| nwb_file_name name of the NWB file | lfp_electrode_group_name the name of this group of electrodes | electrode_group_name electrode group name from NWBFile | electrode_id the unique number for this electrode |
|---|---|---|---|
| tonks20211103_.nwb | all_tets_tonks | 0 | 0 |
| tonks20211103_.nwb | CA1_test | 0 | 0 |
| tonks20211103_.nwb | CA1_test | 0 | 1 |
| tonks20211103_.nwb | CA1_test | 0 | 2 |
| tonks20211103_.nwb | CA1_test | 0 | 3 |
| tonks20211103_.nwb | all_tets_tonks | 1 | 4 |
| tonks20211103_.nwb | CA1_test | 1 | 4 |
| tonks20211103_.nwb | CA1_test | 1 | 5 |
| tonks20211103_.nwb | CA1_test | 1 | 6 |
| tonks20211103_.nwb | CA1_test | 1 | 7 |
| tonks20211103_.nwb | all_tets_tonks | 10 | 40 |
| tonks20211103_.nwb | CA1_test | 10 | 40 |
...
Total: 115
Next we need to select an interval list and the lfp filter we want to use¶
You might need to run
(IntervalList & {"nwb_file_name": nwb_file_name})
to see the list of intervals and similarly
FirFilterParameters()
to see the list of defined filters
from spyglass.common import IntervalList
pd.DataFrame(IntervalList & {"nwb_file_name": nwb_file_name})
| nwb_file_name | interval_list_name | valid_times | |
|---|---|---|---|
| 0 | tonks20211103_.nwb | 01_s1 | [[1635959950.207, 1635960965.1751666]] |
| 1 | tonks20211103_.nwb | 02_r1 | [[1635961196.091, 1635962807.3995333]] |
| 2 | tonks20211103_.nwb | 03_s2 | [[1635963036.529, 1635964533.0212]] |
| 3 | tonks20211103_.nwb | 04_r2 | [[1635972839.0860002, 1635974316.8678665]] |
| 4 | tonks20211103_.nwb | 05_s3 | [[1635974508.528, 1635975759.1054666]] |
| ... | ... | ... | ... |
| 435 | tonks20211103_.nwb | tonks20211103_.nwb_r2_r3_7_franklab_tetrode_hi... | [[1635974153.2324, 1635974153.2374668], [16359... |
| 436 | tonks20211103_.nwb | tonks20211103_.nwb_r2_r3_8_franklab_tetrode_hi... | [[1635972839.0860002, 1635974316.8678665], [16... |
| 437 | tonks20211103_.nwb | tonks20211103_.nwb_r2_r3_8_franklab_tetrode_hi... | [[1635972847.0969, 1635972847.0988998], [16359... |
| 438 | tonks20211103_.nwb | tonks20211103_.nwb_r2_r3_8_franklab_tetrode_hi... | [[1635972839.0860002, 1635983461.2015336]] |
| 439 | tonks20211103_.nwb | tonks20211103_.nwb_r2_r3_LFP_default_differenc... | [[1635972839.0860002, 1635972984.826], [163597... |
440 rows × 3 columns
import numpy as np
orig_interval_list_name = "02_r1"
valid_times = (
IntervalList
& {
"nwb_file_name": nwb_file_name,
"interval_list_name": orig_interval_list_name,
}
).fetch1("valid_times")
new_valid_times = np.asarray([[valid_times[0, 0], valid_times[0, 0] + 100]])
interval_list_name = "test interval2"
interval_key = {
"nwb_file_name": nwb_file_name,
"interval_list_name": interval_list_name,
"valid_times": new_valid_times,
}
IntervalList.insert1(
interval_key,
skip_duplicates=True,
)
IntervalList() & {
"nwb_file_name": nwb_file_name,
"interval_list_name": interval_list_name,
}
| nwb_file_name name of the NWB file | interval_list_name descriptive name of this interval list | valid_times numpy array with start and end times for each interval |
|---|---|---|
| tonks20211103_.nwb | test interval2 | =BLOB= |
Total: 1
Now we create the LFPSelection entry to combine the data, interval list and filter¶
import copy
from spyglass.lfp.v1 import LFPSelection
filter_name = "LFP 0-400 Hz"
filter_sampling_rate = 30_000
lfp_s_key = copy.deepcopy(lfp_eg_key)
lfp_s_key["target_interval_list_name"] = interval_list_name
lfp_s_key["filter_name"] = filter_name
lfp_s_key["filter_sampling_rate"] = filter_sampling_rate
LFPSelection.insert1(lfp_s_key, skip_duplicates=True)
lfp_s_key
{'nwb_file_name': 'tonks20211103_.nwb',
'lfp_electrode_group_name': 'CA1_test',
'target_interval_list_name': 'test interval2',
'filter_name': 'LFP 0-400 Hz',
'filter_sampling_rate': 30000}
LFPSelection() & lfp_s_key
| nwb_file_name name of the NWB file | lfp_electrode_group_name the name of this group of electrodes | target_interval_list_name descriptive name of this interval list | filter_name descriptive name of this filter | filter_sampling_rate sampling rate for this filter |
|---|---|---|---|---|
| tonks20211103_.nwb | CA1_test | test interval2 | LFP 0-400 Hz | 30000 |
Total: 1
Populate the LFP table. Note that this takes 2 hours or so on a laptop if you use all electrodes¶
Note here that populating the LFP table also inserts an LFP entry into LFPOutput, a table that allows us to merge computed and imported lfps
from spyglass.lfp.v1 import LFPV1
LFPV1().populate(lfp_s_key)
We can now look at the LFP table to see the data we've extracted
from spyglass.lfp import LFPOutput
LFPOutput.LFPV1() & lfp_s_key
| merge_id | nwb_file_name name of the NWB file | lfp_electrode_group_name the name of this group of electrodes | target_interval_list_name descriptive name of this interval list | filter_name descriptive name of this filter | filter_sampling_rate sampling rate for this filter |
|---|---|---|---|---|---|
| 2f3c93d5-5d5d-2d47-75b3-c346dddbd312 | tonks20211103_.nwb | CA1_test | test interval2 | LFP 0-400 Hz | 30000 |
Total: 1
lfp_key = {"merge_id": (LFPOutput.LFPV1() & lfp_s_key).fetch1("merge_id")}
lfp_key
{'merge_id': UUID('2f3c93d5-5d5d-2d47-75b3-c346dddbd312')}
LFPOutput & lfp_key
| merge_id | source |
|---|---|
| 2f3c93d5-5d5d-2d47-75b3-c346dddbd312 | LFPV1 |
Total: 1
From the Merge Table, we can get the keys for the LFP data we want to see
lfp_df = (LFPOutput & lfp_key).fetch1_dataframe()
lfp_df
/home/edeno/miniconda3/envs/spyglass/lib/python3.9/site-packages/hdmf/spec/namespace.py:531: UserWarning: Ignoring cached namespace 'hdmf-common' version 1.6.0 because version 1.5.1 is already loaded.
warn("Ignoring cached namespace '%s' version %s because version %s is already loaded."
/home/edeno/miniconda3/envs/spyglass/lib/python3.9/site-packages/hdmf/spec/namespace.py:531: UserWarning: Ignoring cached namespace 'core' version 2.6.0-alpha because version 2.5.0 is already loaded.
warn("Ignoring cached namespace '%s' version %s because version %s is already loaded."
/home/edeno/miniconda3/envs/spyglass/lib/python3.9/site-packages/hdmf/spec/namespace.py:531: UserWarning: Ignoring cached namespace 'hdmf-experimental' version 0.3.0 because version 0.2.0 is already loaded.
warn("Ignoring cached namespace '%s' version %s because version %s is already loaded."
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ... | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| time | |||||||||||||||||||||
| 1.635961e+09 | 12 | 5 | 5 | 12 | -64 | -64 | -61 | -73 | -61 | -56 | ... | -99 | -85 | -34 | -44 | -48 | -47 | -91 | -93 | -77 | -90 |
| 1.635961e+09 | 32 | 20 | 26 | 32 | -120 | -115 | -116 | -137 | -118 | -116 | ... | -177 | -152 | -41 | -65 | -62 | -67 | -161 | -160 | -138 | -161 |
| 1.635961e+09 | -1 | -10 | 0 | -5 | -142 | -140 | -141 | -155 | -144 | -144 | ... | -161 | -154 | -62 | -75 | -68 | -82 | -179 | -175 | -154 | -177 |
| 1.635961e+09 | 7 | -3 | -12 | -10 | -106 | -103 | -113 | -117 | -110 | -94 | ... | -129 | -126 | -34 | -62 | -53 | -67 | -160 | -161 | -127 | -154 |
| 1.635961e+09 | 113 | 98 | 97 | 99 | 38 | 46 | 24 | 24 | 33 | 49 | ... | -33 | -22 | 76 | 45 | 50 | 40 | -46 | -44 | -11 | -34 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 1.635961e+09 | -9 | -7 | 2 | 7 | -4 | -5 | 8 | 0 | -70 | -53 | ... | -11 | -39 | 14 | 25 | 22 | 21 | -43 | -42 | -50 | -39 |
| 1.635961e+09 | -14 | 0 | 3 | 18 | -31 | -28 | -19 | -25 | -89 | -63 | ... | -72 | -95 | -9 | -7 | -13 | -15 | -87 | -85 | -91 | -81 |
| 1.635961e+09 | -7 | 19 | 18 | 32 | -38 | -33 | -23 | -23 | -71 | -31 | ... | -52 | -92 | -21 | -28 | -28 | -27 | -61 | -59 | -52 | -42 |
| 1.635961e+09 | 31 | 50 | 49 | 63 | 1 | 8 | 22 | 23 | -19 | 18 | ... | 21 | -38 | 4 | -12 | -8 | -11 | -11 | -2 | -3 | 9 |
| 1.635961e+09 | 48 | 59 | 64 | 75 | 17 | 25 | 36 | 39 | 1 | 40 | ... | 13 | -31 | 4 | 0 | 0 | 1 | -21 | -17 | -22 | -11 |
100000 rows × 63 columns
Now that we've created the LFP object we can perform a second level of filtering for a band of interest, in this case the theta band¶
We first need to create the filter
from spyglass.common.common_filter import FirFilterParameters
lfp_sampling_rate = LFPOutput.merge_get_parent(lfp_key).fetch1(
"lfp_sampling_rate"
)
filter_name = "Theta 5-11 Hz"
FirFilterParameters().add_filter(
filter_name,
lfp_sampling_rate,
"bandpass",
[4, 5, 11, 12],
"theta filter for 1 Khz data",
)
FirFilterParameters() & {
"filter_name": filter_name,
"filter_sampling_rate": lfp_sampling_rate,
}
| filter_name descriptive name of this filter | filter_sampling_rate sampling rate for this filter | filter_type | filter_low_stop lowest frequency for stop band for low frequency side of filter | filter_low_pass lowest frequency for pass band of low frequency side of filter | filter_high_pass highest frequency for pass band for high frequency side of filter | filter_high_stop highest frequency for stop band of high frequency side of filter | filter_comments comments about the filter | filter_band_edges numpy array containing the filter bands (redundant with individual parameters) | filter_coeff numpy array containing the filter coefficients |
|---|---|---|---|---|---|---|---|---|---|
| Theta 5-11 Hz | 1000 | lowpass | 4.0 | 5.0 | 11.0 | 12.0 | theta filter for 1 KHz data | =BLOB= | =BLOB= |
Total: 1
from spyglass.lfp_band.v1.lfp_band import LFPBandSelection
# assume that we've filtered these electrodes; change this if not
lfp_band_electrode_ids = [28, 32]
# set the interval list name for this band; here we use the same interval as above
interval_list_name = "test interval"
# set the reference to -1 to indicate no reference for all channels
ref_elect = [-1]
# desired sampling rate
lfp_band_sampling_rate = 1000
filter_name = "Theta 5-11 Hz"
LFPBandSelection().set_lfp_band_electrodes(
nwb_file_name=nwb_file_name,
lfp_merge_id=lfp_key["merge_id"],
electrode_list=lfp_band_electrode_ids,
filter_name=filter_name,
interval_list_name=interval_list_name,
reference_electrode_list=ref_elect,
lfp_band_sampling_rate=lfp_band_sampling_rate,
)
LFPBandSelection()
| lfp_merge_id | filter_name descriptive name of this filter | filter_sampling_rate sampling rate for this filter | nwb_file_name name of the NWB file | target_interval_list_name descriptive name of this interval list | lfp_band_sampling_rate the sampling rate for this band | min_interval_len the minimum length of a valid interval to filter |
|---|---|---|---|---|---|---|
| 2f3c93d5-5d5d-2d47-75b3-c346dddbd312 | Theta 5-11 Hz | 1000 | tonks20211103_.nwb | test interval | 100 | 1.0 |
| 2f3c93d5-5d5d-2d47-75b3-c346dddbd312 | Theta 5-11 Hz | 1000 | tonks20211103_.nwb | test interval | 1000 | 1.0 |
Total: 2
Next we add an entry for the LFP Band and the electrodes we want to filter
# assume that we've filtered these electrodes; change this if not
lfp_band_electrode_ids = [28, 32]
# set the interval list name for this band; here we use the same interval as above
interval_list_name = "test interval"
# set the reference to -1 to indicate no reference for all channels
ref_elect = [-1]
# desired sampling rate
lfp_band_sampling_rate = 100
LFPBandSelection().set_lfp_band_electrodes(
nwb_file_name=nwb_file_name,
lfp_merge_id=lfp_key["merge_id"],
electrode_list=lfp_band_electrode_ids,
filter_name=filter_name,
interval_list_name=interval_list_name,
reference_electrode_list=ref_elect,
lfp_band_sampling_rate=lfp_band_sampling_rate,
)
lfp_band_key = (
LFPBandSelection
& {
"merge_id": lfp_key["merge_id"],
"filter_name": filter_name,
"lfp_band_sampling_rate": lfp_band_sampling_rate,
}
).fetch1("KEY")
lfp_band_key
{'lfp_merge_id': UUID('2f3c93d5-5d5d-2d47-75b3-c346dddbd312'),
'filter_name': 'Theta 5-11 Hz',
'filter_sampling_rate': 1000,
'nwb_file_name': 'tonks20211103_.nwb',
'target_interval_list_name': 'test interval',
'lfp_band_sampling_rate': 100}
Check to make sure it worked
LFPBandSelection() & lfp_band_key
| lfp_merge_id | filter_name descriptive name of this filter | filter_sampling_rate sampling rate for this filter | nwb_file_name name of the NWB file | target_interval_list_name descriptive name of this interval list | lfp_band_sampling_rate the sampling rate for this band | min_interval_len the minimum length of a valid interval to filter |
|---|---|---|---|---|---|---|
| 2f3c93d5-5d5d-2d47-75b3-c346dddbd312 | Theta 5-11 Hz | 1000 | tonks20211103_.nwb | test interval | 100 | 1.0 |
Total: 1
from spyglass.lfp_band.v1 import LFPBandV1
LFPBandV1().populate(LFPBandSelection() & lfp_band_key)
LFPBandV1()
| lfp_merge_id | filter_name descriptive name of this filter | filter_sampling_rate sampling rate for this filter | nwb_file_name name of the NWB file | target_interval_list_name descriptive name of this interval list | lfp_band_sampling_rate the sampling rate for this band | analysis_file_name name of the file | interval_list_name descriptive name of this interval list | lfp_band_object_id the NWB object ID for loading this object from the file |
|---|---|---|---|---|---|---|---|---|
| 2f3c93d5-5d5d-2d47-75b3-c346dddbd312 | Theta 5-11 Hz | 1000 | tonks20211103_.nwb | test interval | 100 | tonks20211103_RIY746JTRY.nwb | test interval lfp band 100Hz | bcaa7754-f82b-46c4-bc8a-6cda5a3f7ae4 |
Total: 1
Now we can plot the original signal, the LFP filtered trace, and the theta filtered trace together.¶
Much of the code below could be replaced by a function calls that would return the data from each electrical series
import matplotlib.pyplot as plt
Get the three electrical series objects and the indices of the electrodes we band pass filtered
from spyglass.common import Raw, get_electrode_indices
orig_eseries = (Raw() & {"nwb_file_name": nwb_file_name}).fetch_nwb()[0]["raw"]
orig_elect_indices = get_electrode_indices(orig_eseries, lfp_band_electrode_ids)
orig_timestamps = np.asarray(orig_eseries.timestamps)
[2023-07-10 17:05:22,139][WARNING]: Skipped checksum for file with hash: 8f9a9b20-2997-a09d-1e37-c568394d708e, and path: /stelmo/nwb/raw/tonks20211103_.nwb
WARNING:datajoint:Skipped checksum for file with hash: 8f9a9b20-2997-a09d-1e37-c568394d708e, and path: /stelmo/nwb/raw/tonks20211103_.nwb
/home/edeno/miniconda3/envs/spyglass/lib/python3.9/site-packages/hdmf/spec/namespace.py:531: UserWarning: Ignoring cached namespace 'core' version 2.4.0 because version 2.5.0 is already loaded.
warn("Ignoring cached namespace '%s' version %s because version %s is already loaded."
/home/edeno/miniconda3/envs/spyglass/lib/python3.9/site-packages/pynwb/behavior.py:46: UserWarning: SpatialSeries 'series_0' has data shape (66792, 4) which is not compliant with NWB 2.5 and greater. The second dimension should have length <= 3 to represent at most x, y, z.
warnings.warn("SpatialSeries '%s' has data shape %s which is not compliant with NWB 2.5 and greater. "
/home/edeno/miniconda3/envs/spyglass/lib/python3.9/site-packages/pynwb/behavior.py:46: UserWarning: SpatialSeries 'series_1' has data shape (48950, 4) which is not compliant with NWB 2.5 and greater. The second dimension should have length <= 3 to represent at most x, y, z.
warnings.warn("SpatialSeries '%s' has data shape %s which is not compliant with NWB 2.5 and greater. "
/home/edeno/miniconda3/envs/spyglass/lib/python3.9/site-packages/pynwb/behavior.py:46: UserWarning: SpatialSeries 'series_2' has data shape (98507, 4) which is not compliant with NWB 2.5 and greater. The second dimension should have length <= 3 to represent at most x, y, z.
warnings.warn("SpatialSeries '%s' has data shape %s which is not compliant with NWB 2.5 and greater. "
/home/edeno/miniconda3/envs/spyglass/lib/python3.9/site-packages/pynwb/behavior.py:46: UserWarning: SpatialSeries 'series_3' has data shape (44892, 4) which is not compliant with NWB 2.5 and greater. The second dimension should have length <= 3 to represent at most x, y, z.
warnings.warn("SpatialSeries '%s' has data shape %s which is not compliant with NWB 2.5 and greater. "
/home/edeno/miniconda3/envs/spyglass/lib/python3.9/site-packages/pynwb/behavior.py:46: UserWarning: SpatialSeries 'series_4' has data shape (82313, 4) which is not compliant with NWB 2.5 and greater. The second dimension should have length <= 3 to represent at most x, y, z.
warnings.warn("SpatialSeries '%s' has data shape %s which is not compliant with NWB 2.5 and greater. "
/home/edeno/miniconda3/envs/spyglass/lib/python3.9/site-packages/pynwb/behavior.py:46: UserWarning: SpatialSeries 'series_5' has data shape (81566, 4) which is not compliant with NWB 2.5 and greater. The second dimension should have length <= 3 to represent at most x, y, z.
warnings.warn("SpatialSeries '%s' has data shape %s which is not compliant with NWB 2.5 and greater. "
/home/edeno/miniconda3/envs/spyglass/lib/python3.9/site-packages/pynwb/behavior.py:46: UserWarning: SpatialSeries 'series_6' has data shape (83811, 4) which is not compliant with NWB 2.5 and greater. The second dimension should have length <= 3 to represent at most x, y, z.
warnings.warn("SpatialSeries '%s' has data shape %s which is not compliant with NWB 2.5 and greater. "
lfp_eseries = LFPOutput.fetch_nwb(lfp_key)[0]["lfp"]
lfp_elect_indices = get_electrode_indices(lfp_eseries, lfp_band_electrode_ids)
lfp_timestamps = np.asarray(lfp_eseries.timestamps)
from spyglass.lfp_band import LFPBandOutput
lfp_band_eseries = LFPBandOutput.fetch_nwb(lfp_band_key)[0]["lfp_band"]
lfp_band_elect_indices = get_electrode_indices(
lfp_band_eseries, lfp_band_electrode_ids
)
lfp_band_timestamps = np.asarray(lfp_band_eseries.timestamps)
Get a list of times for the first run epoch and then select a 2 second interval 100 seconds from the beginning
plottimes = [new_valid_times[0][0] + 10, new_valid_times[0][0] + 12]
# get the time indices for each dataset
orig_time_ind = np.where(
np.logical_and(
orig_timestamps > plottimes[0], orig_timestamps < plottimes[1]
)
)[0]
lfp_time_ind = np.where(
np.logical_and(lfp_timestamps > plottimes[0], lfp_timestamps < plottimes[1])
)[0]
lfp_band_time_ind = np.where(
np.logical_and(
lfp_band_timestamps > plottimes[0],
lfp_band_timestamps < plottimes[1],
)
)[0]
plt.plot(
orig_eseries.timestamps[orig_time_ind],
orig_eseries.data[orig_time_ind, orig_elect_indices[0]],
"k-",
)
plt.plot(
lfp_eseries.timestamps[lfp_time_ind],
lfp_eseries.data[lfp_time_ind, lfp_elect_indices[0]],
"b-",
)
plt.plot(
lfp_band_eseries.timestamps[lfp_band_time_ind],
lfp_band_eseries.data[lfp_band_time_ind, lfp_band_elect_indices[0]],
"r-",
)
plt.xlabel("Time (sec)")
plt.ylabel("Amplitude (AD units)")
plt.show()